// vim: filetype=cpp

%TEX2D image = particle

%VERTEX_SHADER

uniform vec3    origin;
uniform float   velocity;
uniform float   time;
uniform float   length;
uniform float   spread;
uniform float   size;
uniform float   alpha;

varying vec2 vTexCoord;
varying vec4 vColor;

void main (void)
{
    vec4 Position;
    Position = gl_ModelViewMatrix * gl_Vertex;
    gl_Position = gl_ProjectionMatrix * Position;
   
//     vTexCoord = gl_Vertex.xy;
    vTexCoord = (gl_Vertex.xy+vec2(1.0,1.0))*.5;

//     vec3 pos = gl_Vertex.xyz + velocity*time;
//     gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(pos, 1);

    float sinz = sin(gl_Vertex.z+time);
    float cosz = cos(gl_Vertex.z+time);
    float sc1 = sinz+1.5;
    float sc2 = cosz+1.5;
    
    float d;
    d = gl_Vertex.z;
    d += time*velocity;
//     d=0.0;

    d = mod(d, 1.0);
    
    
    vec3 pos = origin;
    pos.z -= d * length;
    pos += gl_MultiTexCoord0.xyz;
    pos.xy *= 1.0 + spread*d;
    gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(pos, 1.0);
//     gl_Position.xy += gl_Vertex.xy*.06;
//     gl_Position.xy += gl_Vertex.xy * .1 * vec2(cosz, sinz);
    gl_Position.x += size * (gl_Vertex.x * cosz + gl_Vertex.y * sinz);
    gl_Position.y += size * (gl_Vertex.x * sinz - gl_Vertex.y * cosz);
    
    vColor = vec4(1.0,1.0,1.0, (1.0-d)*alpha);
}

%FRAGMENT_SHADER

uniform sampler2D image;

varying vec2 vTexCoord;
varying vec4 vColor;

void main (void)
{
    vec4 col = texture2D(image, vTexCoord);
    gl_FragColor = col * vColor;
}

